/**
 * Created by chen on 2018/12/24.
 */
//页面初始化
var objectId = 'playerMap0';
var videoMainWndIndexArr=[];
var cameraList = [];
var i = 0;
function init(objectId){
    ocxHtmlLoad(objectId);
    //初始化视频列表 测试数据
    //调后台接口
    cameraList=[
        {videoCode:'040210000003040001',videoName:'崇州站A-大门'},
        {videoCode:'040210000003040001',videoName:'崇州站A-大门'},
        {videoCode:'040210000003040001',videoName:'崇州站A-大门'},
        {videoCode:'040210000003040001',videoName:'崇州站A-大门'},
        {videoCode:'040210000003040001',videoName:'崇州站A-大门'},
        {videoCode:'040210000003040001',videoName:'崇州站A-大门'},
    ];
    cameraList.map(function(item, index){
        $("#video-name"+index).html(item.videoName);
        var videoMainWndIndex = createWindow('playerMap'+index);
        videoMainWndIndexArr.push(videoMainWndIndex);

        openVideo(videoMainWndIndex,item.videoCode,item.videoName,'playerMap'+index);
    });
    console.log(videoMainWndIndexArr);
}
init(objectId);

//点击完变电站 传变电站code
//获取监测点列表
//默认将监测列表前6个展示出   ==

function videoList(objectId,code){
    videoMainWndIndexArr.map(function(item, index){
        stopAllVideo(item, "playerMap"+index);
    });
    //for(var i = 0;i<6;i++){
    //    stopAllVideo(videoMainWndIndexArr[i], "playerMap"+i);
    //}
    videoLists = [];
    //监测点所有数据
    var instation = document.getElementById(objectId).ocxVideoResQuery(code);
     ind = $(instation).find("SubList").attr("SubNum");
    console.log(i);

    $(instation).find("Item").each(
        function () {
            var name = $(this).attr("Name");
            var code = $(this).attr('Code');
            $('<option></option>').appendTo($('#instation')).text(name).attr('value', code);
            $('.table div:nth-child(5)').append("<p code='"+code+"'>"+name+"</p>");
            videoLists.push({videoName:name,videoCode:code});

        });
    $('#instation').multiselect('rebuild');
    console.log(videoLists);
    ////
    //renderVideo(videoLists);
    //展示前6个
    var videoListSix = videoLists.slice(i*6,6*(i+1));
    videoMainWndIndexArr=[];
    videoListSix.map(function(item, index){
        $("#video-name"+index).html(item.videoName);
        //if(videoMainWndIndexArr.length < 4){
        var videoMainWndIndex = createWindow('playerMap'+index);
        videoMainWndIndexArr.push(videoMainWndIndex);
        //}
        openVideo(videoMainWndIndex,item.videoCode,item.videoName,'playerMap'+index);
    });
}
//点击下一页
//传i位置的值
//停止视频后开启6个
function next(i){
    //stopAllVideo();
    var videoListSix = videoLists.slice(i*6,6*(i+1));
    videoListSix.map(function(item, index){
        $("#video-name"+index).html(item.videoName);
        var videoMainWndIndex = createWindow('playerMap'+index);
        videoMainWndIndexArr.push(videoMainWndIndex);
        openVideo(videoMainWndIndex,item.videoCode,item.videoName,'playerMap'+index);
    });
}

//监测点渲染
function renderVideo(data){
    var video = [];
    videoLists = [];
    data.map(function (item,index) {
        video.push(item);
        if(index+1 == data.length || !(index+1)%6){
            videoLists.push(video);
            video = [];
        }
    });
    console.log(videoLists);
}
//renderVideo(cameraList);

//监测点选择
function selectVideo(index){
    var list = cameraList[index];
    //var code = list.videoCode;
    $(".video-name").text("");
    cameraList.map(function(item, index){
        $("#video-name"+index).html(item.videoName);
        var videoMainWndIndex = createWindow('playerMap'+index);
        videoMainWndIndexArr.push(videoMainWndIndex);
        openVideo(videoMainWndIndex,item.videoCode,item.videoName,'playerMap'+index);
    });
}

